package com.sssd;

import com.github.kwhat.jnativehook.GlobalScreen;
import com.github.kwhat.jnativehook.NativeHookException;
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener;
import com.sssd.ui.WindowUi;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.Arrays;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author sssd
 * @update 2023-02-05 21:10
 */

public class Main implements NativeKeyListener {
    public static final WindowUi windowUi = new WindowUi();

    public static void main(String[] args) throws NativeHookException, AWTException {
        System.out.println("插件已启动......");
        GlobalScreen.registerNativeHook();
        GlobalScreen.addNativeKeyListener(new Main());

        Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
        logger.setLevel(Level.ALL);
        logger.setUseParentHandlers(false);

        windowUi.init();

    }

    @Override
    public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent) {
    }

    @Override
    public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) {
        Integer numKey = windowUi.getNumKey();
        if (Objects.isNull(numKey)) {
            return;
        }
        Integer delayTime = windowUi.getDelayTime();
        if (Objects.isNull(delayTime)) {
            return;
        }
        if (nativeKeyEvent.getKeyCode() == numKey) {
            // FIXME: 2023/2/6 马丁投篮包 585
            // FIXME: 2023/2/6 库里投篮包 650
            // FIXME: 2023/2/6 沃尔投篮包 700
            // FIXME: 2023/2/6 里德诺投篮包 540
            // FIXME: 2023/2/6 沃克投篮包 540
            // FIXME: 2023/2/6 老柴投篮包 625
            new NormalBasketPackage().shootBall(Arrays.asList(KeyEvent.VK_D), delayTime);
            System.out.println("投篮已触发......");
        }
    }

    @Override
    public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) {
    }
}
